package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * tb_tag 默认枚举
 *  @author 魏荣杰
 *   @date 2018/12/6 15:20
 */
@Getter
public enum TagEnum {
    /**
     * 退回公海池标签
     */
    TAG_RETURN_PUBLIC(1, XbbRefTypeEnum.CUSTOMER_PUBLIC.getCode(),"returnPublic", "enum.tag.name.tag_return_public", "", 1, "enum.tag.memo.tag_return_public"),
    /**
     * 归档标签
     */
    TAG_ARCHIVED(2, XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), "archived","enum.tag.name.tag_archived", "", 0, "enum.tag.memo.tag_archived"),
    /**
     * 紧急标签
     */
    TAG_EMERGENCY(3, XbbRefTypeEnum.WORK_ORDER.getCode(), "emergency","enum.tag.name.tag_emergency", "", 0, "enum.tag.memo.tag_emergency"),
    /**
     * 紧急标签
     */
    TAG_VERT_EMERGENCY(4, XbbRefTypeEnum.WORK_ORDER.getCode(), "veryEmergency","enum.tag.name.tag_emergency", "", 0, "enum.tag.memo.tag_vert_emergency"),
    /**
     * 机会归档标签
     */
    TAG_ARCHIVED_OPPORTUNITY(5, XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), "archived","enum.tag.name.tag_archived", "", 0, "enum.tag.memo.tag_archived_opportunity"),
    /**
     * 合同归档标签
     */
    TAG_ARCHIVED_CONTRACT(6, XbbRefTypeEnum.CONTRACT.getCode(), "archived","enum.tag.name.tag_archived", "", 0, "enum.tag.memo.tag_archived_contract"),
    /**
     * 报价单归档标签
     */
    TAG_ARCHIVED_QUOTATION(7, XbbRefTypeEnum.QUOTATION.getCode(), "archived", "enum.tag.name.tag_archived", "", 0, "enum.tag.memo.tag_archived_quotation"),

    TAG_OVERDUE(10, XbbRefTypeEnum.PAYMENT.getCode(),"overdue","enum.tag.name.tag_overdue","",0,"enum.tag.memo.tag_overdue"),
    /**
     * 线索退回公海池标签
     */
    TAG_RETURN_PUBLIC_CLUE(8, XbbRefTypeEnum.CLUE_PUBLIC.getCode(),"returnPublic", "enum.tag.name.tag_return_public_clue", "", 1, "enum.tag.memo.tag_return_public_clue"),
    /**
     * 归档标签
     */
    TAG_ARCHIVED_CLUE(9, XbbRefTypeEnum.CLUE.getCode(), "archived","enum.tag.name.tag_archived_clue", "", 0, "enum.tag.memo.tag_archived_clue"),
    /**
     * 对账单归档标签
     */
    TAG_ARCHIVED_STATEMENT(10, XbbRefTypeEnum.CUSTOMER_STATEMENT_STATISTIC.getCode(), "archived","enum.tag.name.tag_archived_clue", "", 0, "enum.tag.memo.tag_archived_statement"),
    /**
     * 订货单归档标签
     */
    TAG_ARCHIVED_ORDER(12, XbbRefTypeEnum.ORDER.getCode(), "archived","enum.tag.name.tag_archived", "", 0, "enum.tag.memo.tag_archived_order"),
    /**
     * 客户转移公海池标签
     */
    TAG_TRANSFER_PUBLIC_CUSTOMER(13,XbbRefTypeEnum.CUSTOMER_TRANSFER.getCode(),"transferPublicCustomer","enum.tag.name.tag_transfer_public_customer", "", 1, "enum.tag.memo.tag_transfer_public_customer"),
    /**
     * 线索转移公海池标签
     */
    TAG_TRANSFER_PUBLIC_CLUE(14, XbbRefTypeEnum.CLUE_TRANSFER.getCode(),"transferPublicClue","enum.tag.name.tag_transfer_public_clue", "", 1, "enum.tag.memo.tag_transfer_public_clue"),

    ;

    /**
     * id
     */
    private final Integer id;
    /**
     * 标签类型
     */
    private final Integer tagType;
    /**
     * 标签别名
     */
    private final String attr;
    /**
     * 标签名称
     */
    private final String name;
    /**
     * 标签资源
     */
    private final String resource;
    /**
     * 标签资源类型
     */
    private final Integer resourceType;
    /**
     * 标签备注信息
     */
    private final String memo;

    TagEnum(Integer id, Integer tagType, String attr,String name, String resource, Integer resourceType, String memo) {
        this.id = id;
        this.tagType = tagType;
        this.attr = attr;
        this.name = name;
        this.resource = resource;
        this.resourceType = resourceType;
        this.memo = memo;
    }

    public static List<TagEnum> getAllEnum() {
        return new ArrayList<>(Arrays.asList(values()));
    }

    /**
     * Description: 根据标签类型获取
     * @param tagType 标签类型
     * @return TagEnum
     * @author 魏荣杰
     * @date 2018/12/6 15:31
     * Modified by:
     */
    public static TagEnum getTagByTagType(Integer tagType) {
        for (TagEnum cache : values()) {
            if (Objects.equals(cache.getTagType(), tagType)) {
                return cache;
            }
        }
        return null;
    }

    public static TagEnum getTagByAttr(String attr) {
        for (TagEnum cache : values()) {
            if (Objects.equals(cache.getAttr(), attr)) {
                return cache;
            }
        }
        return null;
    }

    public String getMemo() {
        return I18nMessageUtil.getMessage(memo);
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

}
